/**
 * Copyright &copy; 2013-2016 山东易科德软件有限公司   All rights reserved.
 */
package cn.net.ecode.modules.cms.web;

import java.util.Date;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.net.ecode.common.persistence.Page;
import cn.net.ecode.common.web.BaseController;
import cn.net.ecode.modules.cms.entity.VisitLog;
import cn.net.ecode.modules.cms.service.VisitLogService;

/**
 * 访问日志Controller
 * @author ThinkGem
 * @version 2015-12-28
 */
@Controller
@RequestMapping(value = "${adminPath}/cms/visitLog")
public class VisitLogController extends BaseController {

	@Autowired
	private VisitLogService visitLogService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public VisitLog get(String id, boolean isNewRecord) {
		return visitLogService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("cms:visitLog:view")
	@RequestMapping(value = {"index", ""})
	public String list(VisitLog visitLog, Model model) {
		// 设置默认时间范围，默认当天
		if (visitLog.getBeginVisitTime() == null){
			visitLog.setBeginVisitTime(new Date());
		}
		if (visitLog.getEndVisitTime() == null){
			visitLog.setEndVisitTime(visitLog.getBeginVisitTime());
		}
		model.addAttribute("visitLog", visitLog);
		return "modules/cms/visitLogIndex";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("cms:visitLog:view")
	@ResponseBody
	@RequestMapping(value = "listData")
	public Page<VisitLog> listData(VisitLog visitLog, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<VisitLog> page = visitLogService.findPage(new Page<VisitLog>(request, response), visitLog); 
		return page;
	}
	
	/**
	 * 统计概况，详情见：VisitLogDao.totalCount
	 */
	@RequiresPermissions("cms:visitLog:view")
	@ResponseBody
	@RequestMapping(value = "totalCount")
	public Map<String, Object> totalCount(VisitLog visitLog, HttpServletRequest request, HttpServletResponse response, Model model) {
		Map<String, Object> resultMap = visitLogService.totalCount(visitLog); 
		return resultMap;
	}

}